import React from 'react';

const useCollapse = (defaultActiveKey = [], defaultInActiveKey = []) => {
    const [activeKey, setActiveKey] = React.useState(defaultActiveKey);

    const allKeys = React.useMemo(() => [...new Set([...defaultActiveKey, ...defaultInActiveKey])], [
        defaultActiveKey,
        defaultInActiveKey
    ]);

    const onChange = key => {
        setActiveKey(key);
    };

    const openAll = () => {
        setActiveKey(allKeys);
    };

    return {
        activeKey,
        onChange,
        openAll
    };
};

export default useCollapse;
